<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		xmlns:xtp="http://www.x2ee.org/xtp/1.0">

<!--DOC
<h1>XTP: XML TRANSFORMER PAGES</h1>

<p>
XTP is a blend and subset of XSP (XML Server Pages) and XSL (XML Stylesheet Language).  Like
XSP (See <a href="http://cocoon.apache.org">Apache Cocoon</a> project at
http://cocoon.apache.org) XTP compiles the Logic Stylesheet to Java and allows the
user to interleave Java and XML constructs.
However, unlike XSP, XTP operates on an XML SAX stream in a "Transformer" capacity,
whereas XSP can only generate a SAX stream.  Being a transformer, XTP utilizes some
constructs from the XSL language, but is not nearly as filled out.</p>

<h3>SIMPLE EXAMPLE</h3>
<pre>
&lt;xtp:template match="root"&gt;
  &lt;root&gt;
    &lt;xtp:logic&gt;
      for( int i=0; i &lt; 3; i++) {
        &lt;foo/&gt;
      }
    &lt;/xtp:logic&gt;
  &lt;/root&gt;
&lt;/xtp:template&gt;
</pre>


<h3>ARCHITECTURE AND DESIGN:</h3>

<p>
A guiding objective behind XTP is to achieve "SAX-like" efficiency.  That is, no DOM structures
are instantiated.  All transformation and processing is achieve on the fly with a minimum
of memory and CPU overhead.  Thus, major tree manipulates possible in XSL are not
supported in XTP.  While this may seem like a drawback, it is not the purpose
of XTP to poses the functionality of XSL.  Rather, IF such functionality is needed,
an XSL transformation can always be used prior to XTP.  In this manner, XTP does NOT
attempt to duplicate the functionality of XSL found in many other very refined products.</p>


<h3>THE XTP.XSL FILE:</h3>
The core technology is this single file (i.e. xtp.xsl).  With it and the instructions below,
a java file can be generated from a XTP file.  How the generated java file is used
is environment dependent and not defined here.

<h3>DOWNLOAD:</h3>

<p>
The entire project including file can be downloaded at:
<a href="http://www.x2ee.org/xtp/xtp.zip">http://www.x2ee.org/xtp/xtp.zip</a>.
<br/>
This file alone can be downloaded at: <a href="http://www.x2ee.org/xtp/xtp.xsl">
http://www.x2ee.org/xtp/xtp.xsl</a>.
<br/>
See also power-point presentation <a href="http://www.x2ee.org/xtp/2319-punte.ppt">
http://www.x2ee.org/xtp/2319-punte.ppt</a>
</p>


<h3>USAGE INSTRUCTIONS:</h3>

<pre>
Step 1: Create an XTP file: i.e. foo.xtp.  See examples and test directories.
Step 2: Process XTP into a Java source code:
	java org.apache.xalan.xslt.Process -in foo.xtp -xsl xtp.xsl -text -out foo.java
Step 3: Compile : javac foo.java
Step 4: Use.  The class above implements the interface org.xml.sax.ContentHandler
which accepts a SAX stream.  But ALSO a contentHandel must be supply to this
transformer as an output.  Use member function setContentHandler().  If you do
not wish to hard-code in the "foo" class definition, but rather cast foo as a
ContentHandler, you will then need java reflection technology to access the
setContentHandler() member function as show below:
	java.lang.Class [] myparams =
	    { java.lang.Class.forName( "org.xml.sax.ContentHandler") };
	java.lang.reflect.Method method =
	    xtpClass.getMethod( "setContentHandler", myparams);
	java.lang.Object [] myargs = { saxContentHandler };
	method.invoke( xtpObject, myargs);

No external compile and control environment is presently supplied or supported.
Rather only this XSL stylesheet
</pre>

<h3>SCHEMA:</h3>
<p>
No XML Schema is available at this time.
</p>

<h3>COPYRIGHT:</h3>
<pre>
Copyright (c) 2003 Candlelight Software
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

    Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.

    Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in
    the documentation and/or other materials provided with the
    distribution.

    Neither the name of the Candlelight Software nor the names of its
    contributors may be used to endorse or promote products derived
    from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</pre>
-->


	<xsl:template match="/xtp:transformer">
<!--DOC
<h3>SUMMARY</h3>
<p>
A single &lt;xtp:transformer&gt; tag is needed as the root element and expected for
the entire page. This tag generates the body of the emitted Java source code.  Note
that the attribute "classname" is required and must match the file name given to
the resulting source code.
</p>

<h3>EXAMPLE</h3>
<pre>
<font color="red"><b>&lt;xtp:transformer&gt;</b></font>
    classname="foo"
    xmlns:xtp="http://www.x2ee.org/xtp/1.0"&gt;

    ......

&lt;/xtp:transformer>
</pre>
-->

import org.twdata.pipeline.*;
import org.twdata.pipeline.stage.AbstractTransformer;
import java.io.OutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.lang.reflect.Constructor;
import org.xml.sax.ContentHandler;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

		<!-- Apply any global structure here -->
		<xsl:apply-templates select="xtp:structure"/>


public class <xsl:value-of select="@classname"/> extends AbstractTransformer {

	/** */
	public boolean developmentFlag = false;

	/* Stack of booleans. True means process next node.  */
	protected java.util.Stack stack = new java.util.Stack();
    

	/** Receive notification of the beginning of a document */
	public void startDocument() throws SAXException {
		contentHandler.startDocument();
		stack.empty();
		stack.push( new Boolean( true));
	}


	// Receive notification of the beginning of an element.
	public void startElement(String namespaceURI, String localName, String qName, org.xml.sax.Attributes atts) throws SAXException {
		//debug("StartElement : " + namespaceURI + " : " + localName + " : " + qName + " : " + atts);

				if( localName == null) {
					error( "startElement() arg localName is null.");
					contentHandler.startElement( namespaceURI,  localName,  qName, atts);
					return;
				}

				if( ((Boolean)(stack.peek())).booleanValue() == true ) {
					stack.push( new Boolean( false));

					if( false ); // Just to get else-if construct started


		<xsl:apply-templates select="xtp:template">
			<xsl:with-param name="section">startElement</xsl:with-param>
		</xsl:apply-templates>

				}

				else {
					stack.push( new Boolean( false));
					// Do not process any nodes
				}
	}


	/**
	 * Receive notification of character data.
	 * Typically we gather up string framents in case there are multiple.
	 */
	public void characters(char[] ch, int start, int length) throws SAXException {

		// =+= how and when do we wish to pass through char content?

		//contentHandler.characters( ch, start, length);
	}


	/**
	 * Receive notification of the end of an element.
	 * The lions-share of software logic is found in this routine.
	 * That is, a case section exists for each element tag that is processed.
	 */
	public void endElement(String namespaceURI, String localName, String qName) throws SAXException {

				if( localName == null) {
					error( "endElement() arg localName is null.");
					contentHandler.endElement( namespaceURI,  localName,  qName);
					return;
				}

				stack.pop();
				if( ((Boolean)(stack.peek())).booleanValue() == true ) {

					if( false);

		<xsl:apply-templates select="xtp:template">
			<xsl:with-param name="section">endElement</xsl:with-param>
		</xsl:apply-templates>

				}
				else
					;
	}


	/**
	 * Receive notification of the end of a document.
	 * Write out document to binary stream.
	 */
	public void endDocument() throws SAXException {
		//debug( "endDocument()");
		contentHandler.endDocument();
	}

	/* These member functions are all required by interface ContentHandler but not presently used */

	// End the scope of a prefix-URI mapping.
	public void endPrefixMapping(String prefix) { }

	// Receive notification of ignorable whitespace in element content.
	public void ignorableWhitespace(char[] ch, int start, int length) { }

	// Receive notification of a processing instruction.
	public void processingInstruction(String target, String data) { }

	// Receive an object for locating the origin of SAX document events.
	public void setDocumentLocator(org.xml.sax.Locator locator) { }

	// Receive notification of a skipped entity.
	public void skippedEntity(String name) { }

	// Begin the scope of a prefix-URI Namespace mapping.
	public void startPrefixMapping(String prefix, String uri) { }

	protected void debug( String str) { System.err.println( "xtp:debug - " + str); }
	protected void error( String str) { System.err.println( "xtp:error - " + str); }


}
	</xsl:template>

	<!--
		XTP:TEMPLATE
		XTP:TEMPLATE
	-->
	<xsl:template match="xtp:template">
	<!--DOC
<h3>SUMMARY</h3>

<p>
This tag operates much like the xsl:template tag.  If and when the element
is encountered in the input stream, it will be replaced by the contents
inside the template body, and recursion is also possible using the
&lt;xtp:apply-templates&gt; tag.  Note that only simple tag names (i.e.
not xpath expressions), and the "*" character are supported as to the
contents of the "match" attribute.
</p>

<p>
On the technical side, this template emits code into both the class
startElement() and endElement() member functions.  The emitted code
is part of a sequence of else-if() statement on the incoming
element tag name.</p>

<h3>EXAMPLE</h3>

<h4>Input</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;root/&gt;
</pre>

<h4>XTP Logic Sheet</h4>
<pre>
&lt;xtp:transformer&gt;
    classname="database"
    xmlns:xtp="http://www.x2ee.org/xtp/1.0"&gt;
  <font color="red"><b>&lt;xtp:template match="root"&gt;</b></font>
    &lt;root&gt;
      ....
    &lt;/root&gt;
  &lt;/xtp:template&gt;
&lt;/xtp:transformer&gt;
</pre>

<h4>Output</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;root&gt;
  ...
&lt;/root&gt;
</pre>
-->
		<xsl:param name="section" />

		<xsl:choose>

			<xsl:when test="$section='startElement'">
					// Process input stream &lt;<xsl:value-of select="@match"/>&gt;.startElement()
					else
					<xsl:if test="@match!='*'">
						if ( localName.equals( "<xsl:value-of select="@match"/>" ))
					</xsl:if>
					{
						org.xml.sax.helpers.AttributesImpl attributes = new org.xml.sax.helpers.AttributesImpl();
						String attributeValue;
					<xsl:apply-templates>
						<xsl:with-param name="section" select="$section"/>
					</xsl:apply-templates>
					}
			</xsl:when>

			<xsl:when test="$section='endElement'">
					// Process input stream &lt;<xsl:value-of select="@match"/>&gt;.endElement()
					else
					<xsl:if test="@match!='*'">
						if ( localName.equals( "<xsl:value-of select="@match"/>" ))
					</xsl:if>
					{
					<xsl:apply-templates>
						<xsl:with-param name="section" select="$section"/>
					</xsl:apply-templates>
					}
			</xsl:when>

		</xsl:choose>

	</xsl:template>




	<!--
		* WILDCARD COPY CONSTRUCTOR
		* WILDCARD COPY CONSTRUCTOR
  -->
  <xsl:template match="*">
<!--DOC
<h3>SUMMARY</h3>

<p>This will copy elements from the users XTP document (in particular XML tags in
the interior of an xtp:template constructs into the output stream flow.</p>

<p>On the technical side, Java source code is emitted into the class startElement()
and end Element() member functions.  A key concept is to emit all startElement()
and endElement() constructs in the class member function startElement()except for the
very last endElement() node, and do this in the class member function endElement().</p>

<p>NOTE HACK: If we are inside a &lt;xtp:logic&gt;, emit all source code in the class
startElement() member function.  This is a hack and starting to look like a
limitation of the strategy.  Proper recursion will thus not follow.</p>

<h3>EXAMPLE</h3>

<h4>Input</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;root/&gt;
</pre>

<h4>XTP Logic Sheet</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;xtp:template match="root"&gt;
  <font color="red"><b>&lt;root&gt;</b></font>
    <font color="red"><b>&lt;foo/&gt;</b></font>
    <font color="red"><b>&lt;bar/&gt;</b></font>
    <font color="red"><b>&lt;yada/&gt;</b></font>
  <font color="red"><b>&lt;/root&gt;</b></font>
&lt;/xtp:template&gt;
</pre>

<h4>Output</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;root&gt;
  &lt;foo/&gt;
  &lt;bar/&gt;
  &lt;yada/&gt;
&lt;/root&gt;
</pre>
-->

		<xsl:param name="section" />

						// XTP:WILDCARD on node &lt;<xsl:copy-of select="name()"/>&gt;
		<xsl:choose>

			<!--
				This Java source code is emitted into the class startElement()
				section inside the appropirate else if() {...} construct for the parent
				<xtp:template match="(name)"> construct.
			-->
			<xsl:when test="$section='startElement'">

						attributes = new org.xml.sax.helpers.AttributesImpl();

				<!-- Copy through attributes -->
				<xsl:for-each select="@*">
						attributes.addAttribute( "", "<xsl:copy-of select="name()"/>", "<xsl:copy-of select="name()"/>", "CDATA", "<xsl:value-of select="."/>");
				</xsl:for-each>

				<!-- IF first child is <xtp:attribute>, insert accordingly -->
				<xsl:if test="name(child::*[1])='xtp:attribute'">
					<xsl:apply-templates select="xtp:attribute">
						<xsl:with-param name="section">attributeSection</xsl:with-param>
					</xsl:apply-templates>
						attributes.addAttribute(
										"",
										"<xsl:value-of select="xtp:attribute/@name"/>",
										"<xsl:value-of select="xtp:attribute/@name"/>",
										"CDATA",
										attributeValue
										);
				</xsl:if>

				<!-- Now emitt startElement() -->
						contentHandler.startElement(
							null,
							"<xsl:copy-of select="name()"/>",
							"<xsl:copy-of select="name()"/>",
							attributes);

				<!-- Recurse -->
				<xsl:apply-templates>
					<xsl:with-param name="section" select="$section"/>
				</xsl:apply-templates>

				<!-- Emit except if last node in list -->
				<!-- =+= BUG HACK: really need "any ancestor" detection expression -->
				<xsl:if test="(position()!=last()-1) or (local-name(..)='logic') or (local-name(../..)='logic')">

						<!-- This must be identical to fragment below -->
						contentHandler.endElement(
							null,
							"<xsl:copy-of select="name()"/>",
							"<xsl:copy-of select="name()"/>");

				</xsl:if>
			</xsl:when>


			<xsl:when test="$section='endElement'">

				<xsl:apply-templates>
					<xsl:with-param name="section" select="$section"/>
				</xsl:apply-templates>


				<!-- Emit if last node in list -->
				<xsl:if test="(position()=last()-1) and (local-name(..)!='logic') and (local-name(../..)!='logic')">

						<!-- This must be identical to fragment above -->
						contentHandler.endElement(
							null,
							"<xsl:copy-of select="name()"/>",
							"<xsl:copy-of select="name()"/>");

				</xsl:if>

			</xsl:when>

		</xsl:choose>

  </xsl:template>


	<!--
		XTP:APPLY-TEMPLATES
		XTP:APPLY-TEMPLATES
	-->
	<xsl:template match="xtp:apply-templates">
<!--DOC
<h3>SUMMARY</h3>
<p>Allow processing of nested elements in the input stream.  Note no "select"
attribute exists at this time.  In addition, this tag CANNOT be used
inside an &lt;xtp:logic&gt; tag for technical reasons.</p>

<p>On the internal technical side, this tag set the top of stack
value to "true" allowing the next nested node to be processed.

<h3>EXAMPLE</h3>

<h4>Input</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;root&gt;
  ...
&lt;/root&gt;
</pre>

<h4>XTP Logic Sheet</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;xtp:template match="root"&gt;
  &lt;bar&gt;
    <font color="red"><b>&lt;xtp:apply-templates/&gt;</b></font>
  &lt;/bar&gt;
&lt;/xtp:template&gt;
</pre>

<h4>Output</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;bar&gt;
  ....
&lt;/bar&gt;
</pre>
-->
		<xsl:param name="section" />

		// XTP:APPLY-TEMPLATES
		<xsl:choose>

			<xsl:when test="$section='startElement'">
						/* xtp:apply-templates - Allow processing of child nodes. */
						stack.pop();
						stack.push( new Boolean( true));
			</xsl:when>

			<xsl:when test="$section='endElement'">
				<!-- Do nothing here -->
			</xsl:when>

		</xsl:choose>

	</xsl:template>




	<!--
		XTP:LOGIC
		XTP:LOGIC
	-->
	<xsl:template match="xtp:logic">
<!--DOC
<h3>SUMMARY</h3>
<p>Enclosed text body will be considered Java source code.
Note that once a &lt;xtp:logic&gt; tag is used, an
&lt;xtp:apply-templates&gt; cannot be nested.  this is a current
limitation of the technology.</p>

<p>On the internal technical side, text body is emitted using
content handler characters() member function.

<h3>EXAMPLE</h3>

<h4>Input</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;root/&gt;
</pre>

<h4>XTP Logic Sheet</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;xtp:template match="root"&gt;
  &lt;foo&gt;
    <font color="red"><b>&lt;xtp:logic&gt;</b></font>
      for( int i=0; i &lt; 3; i++) {
        &lt;bar/&gt;
      }
    &lt;/xtp:logic&gt;
  &lt;/foo&gt;
&lt;/xtp:template&gt;
</pre>

<h4>Output</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;foo&gt;
  &lt;bar/&gt;
  &lt;bar/&gt;
  &lt;bar/&gt;
&lt;/foo&gt;
</pre>
-->
		<xsl:param name="section" />

		<xsl:choose>

			<xsl:when test="$section='startElement'">

				<xsl:apply-templates>
					<xsl:with-param name="section" select="$section"/>
				</xsl:apply-templates>

			</xsl:when>


			<xsl:when test="$section='endElement'">

<!--
				<xsl:apply-templates>
					<xsl:with-param name="section" select="$section"/>
				</xsl:apply-templates>
-->
			</xsl:when>

		</xsl:choose>

	</xsl:template>


	<!--
		XTP:EXPR
		XTP:EXPR
		Convert content into string and pass into contentHandler.characters()
		The conversion pathway is by way of the java.lang.String.valueOf(.) static function.
	-->
	<xsl:template match="xtp:expr">
<!--DOC
<h3>SUMMARY</h3>
<p>Enclosed text body will be considered a Java source expression that
can be evaluated as a string.</p>

<p>On the internal technical side, special provision must be made
as to weather this is used for the purpose of an attribute or not.

<h3>EXAMPLE</h3>

<h4>Input</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;root/&gt;
</pre>

<h4>XTP Logic Sheet</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;xtp:template match="root"&gt;
  &lt;polynomial&gt;
    &lt;xtp:logic&gt;
      for( int i=1; i &le; 3; i++) {
        &lt;item&gt;
          &lt;fundamental&gt;<font color="red"><b>&lt;xtp:expr&gt;</b></font>i&lt;/xtp:expr&gt;&lt;/fundamental&gt;
          &lt;quadratic&gt;<font color="red"><b>&lt;xtp:expr&gt;</b></font>i*i&lt;/xtp:expr&gt;&lt;/quadradic&gt;
          &lt;cubic&gt;<font color="red"><b>&lt;xtp:expr&gt;</b></font>i*i*i&lt;/xtp:expr&gt;&lt;/cubic&gt;
        &lt;item/&gt;
      }
    &lt;/xtp:logic&gt;
  &lt;/polynomial&gt;
&lt;/xtp:template&gt;
</pre>

<h4>Output</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;polynomial&gt;
  &lt;item&gt;
    &lt;fundamental&gt;1&lt;/fundamental&gt;
    &lt;quadratic&gt;1&lt;/quadratic&gt;
    &lt;cubic&gt;1&lt;/cubic&gt;
  &lt;/item&gt;
  &lt;item&gt;
    &lt;fundamental&gt;2&lt;/fundamental&gt;
    &lt;quadratic&gt;4&lt;/quadratic&gt;
    &lt;cubic&gt;8&lt;/cubic&gt;
  &lt;/item&gt;
  &lt;item&gt;
    &lt;fundamental&gt;3&lt;/fundamental&gt;
    &lt;quadratic&gt;9&lt;/quadratic&gt;
    &lt;cubic&gt;27&lt;/cubic&gt;
  &lt;/item&gt;
&lt;/polynomial&gt;
</pre>
-->
	<xsl:param name="section" />

						// XTP:EXPR emitted code
		<xsl:choose>

			<xsl:when test="$section='attributeSection'">
						attributeValue += <xsl:value-of select="."/>;
			</xsl:when>
			<xsl:otherwise>
						contentHandler.characters( String.valueOf( <xsl:value-of select="."/>).toCharArray(), 0, String.valueOf( <xsl:value-of select="."/>).length());
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>



	<!--
		XTP:ATTRIBUTE
		XTP:ATTRIBUTE
	-->
	<xsl:template match="xtp:attribute">
<!--DOC
<h3>SUMMARY</h3>
<p>Attach the specified attribute to the parent element.  Note that
the &lt;xtp:text&gt; tag must be used to attach plain text.</p>

<h3>EXAMPLE</h3>

<h4>Input</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;root/&gt;
</pre>

<h4>XTP Logic Sheet</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;xtp:template match="root"&gt;
  &lt;img&gt;
    <font color="red"><b>&lt;xtp:attribute name="href"&gt;</b></font>
        &lt;xtp:text&gt;http://images/&lt;/xtp:text&gt;
        &lt;xtp:expr&gt;1*2*3*4*5&lt;/xtp:expr&gt;
        &lt;xtp:text&gt;.gif&lt;/xtp:text&gt;
    &lt;/xtp:attribute&gt;
  &lt;/img&gt;
&lt;/xtp:template&gt;
</pre>

<h4>Output</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;img href="http://images/120.gif" /&gt;
</pre>

-->
		<xsl:param name="section" />

		<xsl:if test="$section='attributeSection'">
						// XTP:ATTRIBUTE emitt code
						attributeValue = new String();
			<xsl:apply-templates>
				<xsl:with-param name="section">attributeSection</xsl:with-param>
			</xsl:apply-templates>

		</xsl:if>

	</xsl:template>




	<!--
		XTP:TEXT
		XTP:TEXT
	-->
	<xsl:template match="xtp:text">
<!--DOC
<h3>SUMMARY</h3>
<p>Output of general text into character stream or
for use to create attributes.</p>

<h3>EXAMPLE</h3>

<h4>Input</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;root/&gt;
</pre>

<h4>XTP Logic Sheet</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;xtp:template match="root"&gt;
  &lt;img&gt;
    &lt;xtp:attribute name="href"&gt;
        <font color="red"><b>&lt;xtp:text&gt;</b></font>http://images/&lt;/xtp:text&gt;
        &lt;xtp:expr&gt;1*2*3*4*5&lt;/xtp:expr&gt;
        <font color="red"><b>&lt;xtp:text&gt;</b></font>.gif&lt;/xtp:text&gt;
    &lt;/xtp:attribute&gt;
  &lt;/img&gt;
&lt;/xtp:template&gt;
</pre>

<h4>Output</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;img href="http://images/120.gif" /&gt;
</pre>
-->
	<xsl:param name="section" />
						// XTP:TEXT emitted code
		<xsl:choose>

			<xsl:when test="$section='attributeSection'">
						attributeValue += "<xsl:value-of select="."/>";
			</xsl:when>
			<xsl:otherwise>
						contentHandler.characters(
							String.valueOf( "<xsl:value-of select="."/>").toCharArray(),
							0,
							String.valueOf( "<xsl:value-of select="."/>").length()  );
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>


	<!--
		XTP:COPY
		XTP:COPY
	-->
	<xsl:template match="xtp:copy">
<!--DOC
<h3>SUMMARY</h3>
<p>Copy the input stream element and attributes to the output stream.</p>

<h3>EXAMPLE</h3>

<h4>Input</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;root&gt;
  &lt;foo&gt;
    &lt;bar/&gt;
    &lt;yada/&gt;
  &lt;/foo&gt;
&lt;/root&gt;
</pre>

<h4>XTP Logic Sheet</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;xtp:template match="*"&gt;
  <font color="red"><b>&lt;xtp:copy&gt;</b></font>
    &lt;xtp:apply-templates/&gt;
  &lt;/xtp:copy&gt;
&lt;/xtp:template&gt;
</pre>

<h4>Output</h4>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;root&gt;
  &lt;foo&gt;
    &lt;bar/&gt;
    &lt;yada/&gt;
  &lt;/foo&gt;
&lt;/root&gt;
</pre>
-->
		<xsl:param name="section" />

						// XTP:COPY
		<xsl:choose>

			<xsl:when test="$section='startElement'">
						contentHandler.startElement(
							namespaceURI,
							localName,
							qName,
							atts);

				<!-- Recurse -->
				<xsl:apply-templates>
					<xsl:with-param name="section" select="$section"/>
				</xsl:apply-templates>

			</xsl:when>


			<xsl:when test="$section='endElement'">

				<!-- Recurse -->
				<xsl:apply-templates>
					<xsl:with-param name="section" select="$section"/>
				</xsl:apply-templates>

						contentHandler.endElement(
							namespaceURI,
							localName,
							qName);
			</xsl:when>

		</xsl:choose>
	</xsl:template>

	<!--
		XTP:STRUCTURE
		XTP:STRUCTURE
	-->
	<xsl:template match="xtp:structure">
<!--DOC
<h3>SUMMARY</h3>
<p>Use to insert java code in more proprietary areas of dynamically created XTP.java document.</p>

<h3>EXAMPLE:</h3>

<pre>
<font color="red"><b>&lt;xtp:structure&gt;</b></font>
  &lt;xtp:include&gt;java.io.*&lt;/xtp:include&gt;
  &lt;xtp:include&gt;java.util.Random&lt;/xtp:include&gt;
&lt;/xtp:structure&gt;
</pre>
-->
		<xsl:apply-templates/>
	</xsl:template>


	<!--
		XTP:INCLUDE
		XTP:INCLUDE
		Use to insert java import statements.
	-->
	<xsl:template match="xtp:include">
<!--DOC
<h3>SUMMARY</h3>
<p>Use to insert java import statements.</p>

<h3>EXAMPLE:</h3>

<pre>
&lt;xtp:structure&gt;
  <font color="red"><b>&lt;xtp:include&gt;</b></font>java.io.*&lt;/xtp:include&gt;
  <font color="red"><b>&lt;xtp:include&gt;</b></font>java.util.Random&lt;/xtp:include&gt;
&lt;/xtp:structure&gt;
</pre>
-->
import <xsl:value-of select="."/>;
	</xsl:template>


	<!--
		XTP:VALUE-OF
		XTP:VALUE-OF
		=+=

	<xsl:template match="xtp:value-of">
		04
	</xsl:template>
-->


</xsl:stylesheet>